package backup;

import java.awt.Choice;
import java.awt.Color;
import java.awt.FlowLayout;
import java.awt.GridLayout;
import java.awt.Panel;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.awt.event.KeyEvent;
import java.awt.event.KeyListener;

import org.havi.ui.HContainer;
import org.havi.ui.event.HRcEvent;

import device.DeviceHelper;

public class DeviceRevome extends HContainer implements KeyListener {

    private final MainMenu mainMenu;

    private Panel panel;

    private Choice choice;

    private final Render render;

    public DeviceRevome(int i, int j, int k, int l, MainMenu mainMenu) {
        this.mainMenu = mainMenu;
        render = new Render();
        this.addKeyListener(this);
        Componentes();
        this.add(panel);
        panel.repaint();
        repaint();
    }

    private void Componentes() {
        panel = new Panel();
        panel.setSize(500, 500);
        panel.setBackground(Color.WHITE);
        panel.setLocation(115, 45);
        panel.setLayout(new FlowLayout());

        render.getLabel("Excluir Equipamento", panel);

        Panel p1 = render.getPanel(new GridLayout(2, 2), panel);

        render.getLabel("Equipamento", p1);

        choice = render.getCombo(DeviceHelper.getInstance().getDevicesNames(), p1);

        render.getButton("Excluir", p1, new ActionListener() {

            public void actionPerformed(ActionEvent e) {
                System.out.println("removeu: " + choice.getSelectedItem());
                DeviceHelper.getInstance().removeDevice(choice.getSelectedItem());
                mainMenu.removePanelScene(DeviceRevome.this);
                //DeviceRevome.this.requestFocus();
            }
        });

        render.getButton("Voltar", p1, new ActionListener() {

            public void actionPerformed(ActionEvent e) {
                System.out.println("Voltou");
                mainMenu.removePanelScene(DeviceRevome.this);
            }
        });
    }

    public void keyPressed(KeyEvent e) {
        if (e.getKeyChar() == HRcEvent.VK_LEFT) {} else if (e.getKeyChar() == HRcEvent.VK_RIGHT) {} else if (e.getKeyChar() == HRcEvent.VK_ESCAPE) {
            mainMenu.removePanelScene(this);
        }
    }

    public void keyReleased(KeyEvent e) {
    // TODO Auto-generated method stub

    }

    public void keyTyped(KeyEvent e) {
    // TODO Auto-generated method stub

    }

}
